<?php 

	class Translation  extends Object {
		/**
		 * Hold an instance of the class
		 * @var
		 */
		private static $_instance = null;
		private $model = null;
		private $systemModel = null;
		
		/**
		 * A private constructor
		 * Prevents direct creation of object
		 */
		public function __construct(){

			$this->model = new TranslationModel();
			$this->systemModel = SystemModel::getInstance();
		}
	
	
	/**
		 * The singleton method
		 * @return
		 */
		public static function getInstance(){
			if (!self::$_instance instanceof self)
			self::$_instance = new self;
	
			return self::$_instance;
		}
		
		// systemova cast
		public $translation = array();
		
		public static function getStaticTranslation($id_language = false){
			
			$model = new TranslationModel();
			$systemModel = SystemModel::getInstance();
			
			if(!$id_language){
				$lang = $systemModel->getCurrentLanguage();
				$id_language = $lang[0]["id_language"];
			}
			
			$translations = $model->getTranslations($id_language);
			
			$translation = array();
			
			foreach($translations as $t){
				$translation[$t["key"]] = $t["translation"];
			}

			return $translation;
		}
		
		public static function getStaticTranslationByKey($key){
			
			$translations = self::getStaticTranslation();
			
			foreach($translations as $k => $value){
				if($k == $key) return $value;
			}
			
			// TODO pokud translace neexistuje, vytvorime ji
		}
		
		public static function addTranslation($key, $value = ""){
			$model = new TranslationModel();
			
			return $model->addTranslation($key, $value);
			
		}
		
		public static function editTranslation($key, $value, $id_language){
			$model = new TranslationModel();
			
			return $model->editTranslation($key, $value, $id_language);
		}
}

?>